<template>
<view>
<!--pages/topicality/xiaofeiquan/xiaofeiquan.wxml-->
<!--<import src="../../../webview/contact.wxml"></import>-->
<!-- <template is="inContact" data="{{showtk}}" /> -->
<view>
  <!-- 主图 -->
  <image src="http://imgbdb3.bendibao.com/xcx/20207/10/2020710143038_35235.png" class="main-img"></image>
  <!-- 按地区查看学校的分数线 -->
  <view class="city-box">
    <text>{{city}}</text>
  </view>
  <view class="change-city">
    <view style="display: flex;align-items: center;">
      <text style="margin-left: 70rpx;">切换城市:</text>
      <picker @change="bindProv" :value="pindex" :range="provPick">
        <view class="sel-city">
          <view class="picker">
            <text>{{provPick[pindex]}}</text>
          </view>
          <image src="/static/images/dwicon.png"></image>
        </view>
      </picker>
      <picker @change="bindCity" :value="cindex" :range="cityPick">
        <view class="sel-city">
          <view class="picker">
            <text>{{cityPick[cindex]}}</text>
          </view>
          <image src="/static/images/dwicon.png"></image>
        </view>
      </picker>
    </view>
    <view class="search">
      <view class="search-box">
        <input placeholder="请输入学校名称查询" placeholder-style="color:#A7A6A6;font-size:25rpx;" @confirm="searchQu" @input="inputQu">
      </view>
      <view class="chaxun" @tap="searchBtn">查询</view>
    </view>
  </view>
  <!-- 内容 -->
  <view class="yq-content">
    <view v-for="(info, index) in schoolData" :key="index" class="fenshu-box">
      <view class="school-title" @tap="bindClick" :data-index="index">
        <view class="school-box">
          <image src="/static/images/sys/xf_icon2.png"></image>
          <text>{{info.name}}</text>
        </view>
        <image class="xqicon" :src="info.showSpread?'/static/images/sys/shang.png':'/static/images/sys/xia.png'"></image>
      </view>
      <view class="school-content" v-if="info.showSpread">
        <view class="flex-row" style="margin-bottom:30rpx;" v-if="info.addr">
          <view class="text1">学校地址</view>
          <view class="text2" style="margin-left:50rpx;">{{info.addr}}</view>
        </view>
        <view class="flex-row" style="margin-bottom:30rpx;" v-if="info.schooltype">
          <view class="text1">办学类型</view>
          <view class="text2" style="margin-left:50rpx;">{{info.schooltype}}</view>
        </view>
        <view class="flex-row" style="margin-bottom:30rpx;" v-if="info.tel" @tap="callBtn" :data-tel="info.tel">
          <view class="text1">学校电话</view>
          <view class="text2" style="margin-left:50rpx;">{{info.tel}}
            <text style="color:#5195DD">【立即拨打】</text>
          </view>
        </view>
        <view class="flex-row" style="margin-bottom:30rpx;" v-if="info.web">
          <view class="text1">学校网址</view>
          <text class="text2" style="margin-left:50rpx;word-break:break-all;" selectable="true">{{info.web}}</text>
        </view>
        <!-- 查看更多 -->
        <navigator class="see-more" :url="'./school?id=' + info.pid + '&citycode=' + info.citycode" hover-class="none">
          <view>查看录取分数线</view>
        </navigator>
      </view>
    </view>
  </view>


  <!-- 导粉 -->
  <view class="daofen" v-if="infoData.daofen">
    <rich-text :nodes="infoData.daofen.content" style="user-select:text;-webkit-user-select:text">
    </rich-text>
  </view>

</view>
<!-- 快捷导航 -->
<fastnav :qrcodeimg="qrcodeimg" :citycode="citycode" :showNav="showNav" :showShare="showShare"></fastnav>
</view>
</template>

<script>
// pages/topicality/xiaofeiquan/xiaofeiquan.js
//获取应用实例
const app = getApp();
const util = require("../../../../utils/util.js");
var QQMapWX = require("../../../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js");
var qqmapsdk = new QQMapWX({
  key: 'KR7BZ-XSQ3P-VGFD7-LNRZL-E7PXE-STF76'
});
import fastnav from "../../../../component/fastnav/fastnav";

export default {
  data() {
    return {
      citycode: "sz",
      city: '深圳',
      province: '广东',
      pindex: 0,
      cindex: 0,
      cityPick: ["选择城市"],
      showtk: false,
      showNav: true,
      // 快捷导航是否展开
      showShare: true // 显示分享按钮
      ,
      provPick: [],
      schoolData: [],
      qrcodeimg: "",
      cityArray: "",
      citylist: "",
      infoData: "",
      daofen: "",
      schoolValue: ""
    };
  },

  components: {
    fastnav
  },
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    util.getUrl(app.globalData.url).then(res => {
      this.getProvinceData(options.city);
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.infoData ? this.infoData.title : "2020正规高校名单查询"
    };
  },
  // 分享朋友圈
  onShareTimeline: function () {
    return {
      title: this.infoData ? this.infoData.title : "2020正规高校名单查询",
      imageUrl: "http://imgbdb3.bendibao.com/xcx/20207/06/2020706100258_94734.png",
      query: {
        city: this.citycode
      }
    };
  },
  methods: {
    // 定位
    getLocation() {
      qqmapsdk.reverseGeocoder({
        success: res => {
          let city = res.result.address_component.city; // let city="芜湖市";

          let citydata = this.citylist.filter(v => {
            if (city.indexOf(v.cityname) != -1) {
              return v;
            }
          });

          if (citydata != '' && city.indexOf(this.city) == -1) {
            uni.showModal({
              content: '您当前定位城市为' + city + '\n是否需要切换到' + city + '2020正规高校名单查询？',
              success: res => {
                if (res.confirm) {
                  // let citydata = this.data.citylist.filter(v => {
                  //   if (city.indexOf(v.cityname) != -1) {
                  //     return v;
                  //   }
                  // });
                  this.setData({
                    city: Array.isArray(citydata) ? citydata[0].cityname : this.city,
                    citycode: Array.isArray(citydata) ? citydata[0].citycode : this.citycode,
                    province: Array.isArray(citydata) ? citydata[0].province : this.province,
                    cityPick: ["选择城市"]
                  });
                  let clist = [];
                  this.provPick.forEach((v, k) => {
                    if (v == this.province) {
                      this.setData({
                        pindex: k
                      });
                    }
                  });
                  this.cityArray[this.pindex].citylist.forEach(v => {
                    clist.push(v.cityname);
                  });
                  this.setData({
                    cityPick: this.cityPick.concat(clist)
                  });
                  this.cityPick.forEach((v, k) => {
                    if (v == this.city) {
                      this.setData({
                        cindex: k
                      });
                    }
                  }); // 获取城市公众号二维码

                  this.getQrcode(this.citycode);
                  this.getInfoData(this.citycode);
                }
              }
            });
          }
        }
      });
    },

    // 获取城市公众号二维码
    getQrcode(citycode) {
      util.cityConfig(citycode).then(res => {
        this.setData({
          qrcodeimg: res.qrcode
        });
      });
    },

    // 获取城市
    getProvinceData(optcode) {
      let data = {
        action: 'mulu',
        type: "city"
      };
      util.request('zhuanti.php', data).then(res => {
        this.setData({
          cityArray: res.data.data.city
        });
        let provPick = [];
        let citylist = [];
        let clist = [];
        this.cityArray.forEach(v => {
          v.citylist.forEach(v => {
            citylist.push(v);
          });
          provPick.push(v.province);
          this.setData({
            provPick,
            citylist
          });
        });

        if (this.citylist) {
          this.citylist.forEach((v, k) => {
            if (optcode == v.citycode) {
              this.setData({
                citycode: v.citycode,
                city: v.cityname,
                province: v.province
              });
            } else {
              this.setData({
                citycode: this.citycode,
                city: this.city,
                province: this.province
              });
            }
          });
        }

        this.provPick.forEach((v, k) => {
          if (v == this.province) {
            this.setData({
              pindex: k
            });
          }
        });
        this.cityArray[this.pindex].citylist.forEach(v => {
          clist.push(v.cityname);
        });
        this.setData({
          cityPick: this.cityPick.concat(clist)
        });
        this.cityPick.forEach((v, k) => {
          if (v == this.city) {
            this.setData({
              cindex: k
            });
          }
        }); // 获取城市公众号二维码

        this.getQrcode(this.citycode);
        this.getInfoData();

        if (this.citylist != "" && Array.isArray(this.citylist)) {
          // 获取定位
          this.getLocation();
        }
      });
    },

    // 获取数据
    getInfoData(citycode) {
      let data = {
        action: 'mulu',
        citycode: citycode ? citycode : this.citycode
      };
      util.request('zhuanti.php', data).then(res => {
        if (res.data.data.daofen) {
          res.data.data.daofen.content = res.data.data.daofen.content.replace(/<p([\s\w"=\/\.:;]+)((?:(="[^"]+")))/ig, '<p').replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p').replace(/<p([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/ig, '<p').replace(/<p>/ig, '<p class="p_class">').replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1').replace(/<img/gi, '<img style="width:100%;height:auto"'); // .replace(/<span>/ig, '<p class="p_class">')
        }

        if (res.data.data.daxue) {
          res.data.data.daxue.forEach((v, k) => {
            if (k == 0) {
              v.showSpread = true;
            } else {
              v.showSpread = false;
            }
          });
        }

        uni.setNavigationBarTitle({
          title: res.data.data ? res.data.data.title : "2020正规高校名单查询"
        });
        this.setData({
          infoData: res.data.data,
          schoolData: res.data.data.daxue,
          daofen: res.data.data.daofen
        });
      });
    },

    // 搜索学校
    searchData(value) {
      let searchRes = [];

      if (this.schoolData) {
        searchRes = this.infoData.daxue.filter(v => {
          if (v.name.includes(value)) {
            return v;
          }
        });
      }

      if (searchRes != '') {
        this.setData({
          schoolData: searchRes
        });
        this.schoolData.forEach((v, k) => {
          if (k == 0) {
            v.showSpread = true;
          } else {
            v.showSpread = false;
          }
        });
        this.setData({
          schoolData: this.schoolData
        });
      } else {
        uni.showModal({
          content: '未找到改学校信息，请确定学校名称重新查询！',
          showCancel: false,
          confirmText: "我知道了"
        });
      }
    },

    // 省份选择
    bindProv: function (e) {
      this.setData({
        pindex: e.detail.value,
        cindex: 0,
        cityPick: ["选择城市"]
      });
      let clist = [];
      this.cityArray[this.pindex].citylist.forEach(v => {
        clist.push(v.cityname);
      });
      this.setData({
        cityPick: this.cityPick.concat(clist)
      });
    },

    // 城市选择
    bindCity(e) {
      this.setData({
        cindex: e.detail.value
      });
      let cityname = this.cityPick[this.cindex];

      if (this.citylist) {
        this.citylist.forEach(v => {
          if (v.cityname == cityname) {
            let citycode = v.citycode;
            this.setData({
              citycode,
              city: cityname
            });
          }
        });
      } // 获取城市公众号二维码


      this.getQrcode(this.citycode);
      this.getInfoData(this.citycode);
    },

    // 是否展开数据
    bindClick(e) {
      // this.data.infoData.daxue
      let index = e.currentTarget.dataset.index;
      this.schoolData.forEach((v, k) => {
        if (k == index) {
          v.showSpread = !v.showSpread;
        }
      });
      this.setData({
        schoolData: this.schoolData
      });
    },

    // 拨打电话
    callBtn(e) {
      let telNumber = e.currentTarget.dataset.tel;
      uni.makePhoneCall({
        phoneNumber: telNumber
      });
    },

    // 进入客服会话
    contact() {
      this.setData({
        showtk: false
      });
    },

    // 关闭
    close() {
      this.setData({
        showtk: false
      });
    },

    // 搜索输入事件
    inputQu(e) {
      let schoolValue = e.detail.value;
      this.setData({
        schoolValue
      });
    },

    // 搜索区域
    searchQu(e) {
      let schoolValue = e.detail.value;
      this.setData({
        schoolValue
      });
      this.searchData(schoolValue);
    },

    // 查询按钮
    searchBtn() {
      this.searchData(this.schoolValue);
    },

    // 查看详情点击事件
    seeDetail(e) {
      let id = e.currentTarget.dataset.id;
      let citycode = e.currentTarget.dataset.citycode;
      let url = e.currentTarget.dataset.url;
      let type = e.currentTarget.dataset.type;
      let title = e.currentTarget.dataset.title;

      if (id != 0) {
        uni.navigateTo({
          url: '/pages/article/detail/detail?id=' + id + '&type=' + type + '&city=' + citycode
        });
      } else {
        this.setData({
          showtk: true
        });
        util.navContact(title, url);
      }
    },

    /**
     * 页面滑动事件的处理函数
     */
    onPageScroll: function (e) {
      this.setData({
        showNav: false
      });
    }
  }
};
</script>
<style>
/* pages/topicality/xiaofeiquan/xiaofeiquan.wxss */
.main-img{width: 100%;height: 276rpx;}
.city-box{background: #ffffff;border-radius: 35rpx;padding: 10rpx 30rpx;position: absolute;
top: 40rpx;right: 30rpx;}
.city-box text{font-size: 30rpx;font-weight: bolder;}
.city-box image{width: 23rpx;height: 15rpx;margin-left: 10rpx;}
.change-city{background:rgba(255,255,255,1);box-shadow:0rpx 6rpx 6rpx rgba(0,0,0,0.16);
opacity:1;border-radius:20rpx;padding:30rpx 0rpx;position: absolute;top:235rpx;width: 90%;
margin-left: 36rpx;}
.change-city text{font-size:28rpx;font-family:PingFang SC;font-weight:bold;line-height:36rpx;
color:rgba(20,20,20,1);opacity:1;width: 130rpx;text-align: center;white-space:nowrap;}
.sel-city{display: flex;align-items: center;margin-left: 70rpx;}
.sel-city image{width: 19rpx;height: 10rpx;margin-left: 30rpx}

.search{display: flex;align-items: center;margin: 30rpx 50rpx 20rpx 60rpx;}
.search-box{background:rgba(238,238,238,1);opacity:1;border-radius:28rpx;padding: 8rpx 30rpx;flex: 1}
.search-box input{font-size: 25rpx;font-family:PingFang SC;font-weight:500;line-height:32rpx;}
.chaxun{background:rgba(81,149,221,1);border-radius:28rpx;margin-left: 20rpx;
font-size:25rpx;font-family:PingFang SC;font-weight:500;line-height:32rpx;
color:rgba(255,255,255,1);opacity:1;padding: 10rpx 30rpx;}
.renew{font-size:22rpx;font-family:PingFang SC;font-weight:300;line-height:26rpx;
color:rgba(184,184,184,1);opacity:1;float:right;margin-right: 50rpx;}

.yq-content{margin: 230rpx 36rpx 30rpx 36rpx;}
.fenshu-box{margin-bottom: 30rpx;}
.school-title{display: flex;flex-direction: row;align-items: center;justify-content: space-between;}
.school-box{display: flex;flex-direction: row;align-items: center;}
.school-box text{font-size:34rpx;font-family:PingFang SC;font-weight:bold;
line-height:44rpx;color:rgba(20,20,20,1);opacity:1;}
.school-box image{width: 18rpx;height: 26rpx;margin-right: 15rpx;}
.xqicon{width: 55rpx;height: 55rpx;}

.school-content{background:rgba(242,244,252,1);opacity:1;border-radius:20rpx;padding: 40rpx 36rpx 40rpx 36rpx;margin-top: 34rpx;}
.flex-row{display: flex;flex-direction: row;align-items: flex-start;}
.flex-col{display: flex;flex-direction: column;}
.text1{font-size:32rpx;font-family:PingFang SC;font-weight:500;
line-height:44rpx;color:rgba(20,20,20,1);opacity:1;white-space:nowrap;  }
.text2{font-size:32rpx;font-family:PingFang SC;font-weight:500;
line-height:44rpx;color:#5a5a5a;opacity:1;}
.score-box{margin: 40rpx 15rpx 10rpx 15rpx;}
.score-flex{display: flex;flex-direction: row;align-items: center;justify-content: space-between;}
.score{display: flex;flex-direction: row;align-items: center;justify-content: space-between;}
.text3{font-size:30rpx;font-family:PingFang SC;font-weight:500;color:#999999;opacity:1;
margin-bottom: 30rpx; width: 90rpx;}
.text3:last-child{width: 120rpx;text-align: center;}
.text4{font-size:30rpx;font-family:PingFang SC;font-weight:500;color:#000000;opacity:1;margin-bottom: 30rpx;width: 90rpx;}
.text4:last-child{width: 120rpx;text-align: center;}

/* 查看更多 */
.see-more{display: flex;justify-content: center;margin: 0rpx 0;}
.see-more view{background-color: #ffffff;padding: 20rpx 40rpx;font-size:26rpx;border-radius:12rpx;font-family:PingFang SC;font-weight:600;color: #5195DD;text-align: center;white-space:nowrap;}


/* 导粉 */
.daofen{margin-bottom:80rpx;text-align: center;}
.p_class{margin:10rpx 30rpx;line-height: 50rpx;}

</style>